﻿using System;
using System.Collections.Generic;
using System.Linq;
using DeepZoomPivotConstructor.PivotLib;
using HtmlAgilityPack;
using PivotPhysicsPlotsGenerator.Utilities;

namespace PivotPhysicsPlotsGenerator.ATLAS
{
    class ParseTableRowForImages
    {
        public ParseTableRowForImages(Uri baseUri)
        {
            BaseUri = baseUri;
        }

        /// <summary>
        /// Given a row of a table, see if we can find some images in it...
        /// We assume each row is independent for this scan - we aren't passing
        /// any information between rows.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public IEnumerable<PivotImage> Process(HtmlNode node)
        {
            ///
            /// Get all the info we can out of each possible cell!
            /// 

            var cellProcessor = new CellInfoConverter(BaseUri);
            var cellInfo = node.ScanSubNodes("td").SelectMany(cell => cellProcessor.ProcessCell(cell));
            return cellInfo;
        }

        private Uri BaseUri { get; set; }
    }
}
